﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;

namespace DataProcessor.Repository
{
    public class DbConnectionFactory
    {
        private static readonly string ConnectionString;
        private static readonly string DatabaseType;

        static DbConnectionFactory()
        {
            var collection = ConfigurationManager.ConnectionStrings["connectionString"];
            ConnectionString = collection.ConnectionString;
            DatabaseType = collection.ProviderName.ToLower();
        }

        public static IDbConnection CreateDbConnection()
        {
            IDbConnection connection = null;
            switch (DatabaseType)
            {
                case "system.data.sqlclient":
                    connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
                    break;
                case "mysql":
                    //connection = new MySql.Data.MySqlClient.MySqlConnection(connectionString);
                    break;
                case "oracle":
                    //connection = new Oracle.DataAccess.Client.OracleConnection(connectionString);
                    //connection = new System.Data.OracleClient.OracleConnection(connectionString);
                    break;
                case "db2":
                    connection = new System.Data.OleDb.OleDbConnection(ConnectionString);
                    break;
                default:
                    connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
                    break;
            }
            return connection;
        }
    }
}
